import { Fragment } from '@/components/Fragment';
import { Flex, ToggleButton } from '@aws-amplify/ui-react';
import { Example, ExampleCode } from '@/components/Example';
import { ComponentClassTable } from '@/components/ComponentClassTable';
import StandardHTMLAttributes from '@/components/StandardHTMLAttributes.mdx';
import ThemeExample from '@/components/ThemeExample.mdx';
import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay';
import { ToggleButtonDemo } from './demo';
import {
ControlledToggleButtonExample,
DefaultToggleButtonExample,
DefaultToggleButtonGroupExample,
DisabledToggleButtonExample,
ExclusiveToggleButtonGroupExample,
SelectionRequiredToggleButtonGroupExample,
ToggleButtonSizeExample,
ToggleButtonStylePropsExample,
ToggleButtonVariationsExample,
ToggleButtonThemeExample,
} from './examples';
## Demo
## Usage
Import the ToggleButton primitive.
```jsx file=./examples/DefaultToggleButtonExample.tsx
```
### Controlled component
A toggle button can be a controlled component when given `isPressed` prop and `onChange` prop must be provided in this case.
```jsx file=./examples/ControlledToggleButtonExample.tsx
```
### Sizes
Use the `size` prop to change the Button size. Available options are `small`, `large`, and none (default).
```jsx file=./examples/ToggleButtonSizeExample.tsx
```
### Variations
Use the `variation` prop to change the Button variation. Available options are `primary`, `link`, and none (default).
```jsx file=./examples/ToggleButtonVariationsExample.tsx
```
### Disabled
A disabled toggle button will not be able to switch state and will not be focusable.
```jsx file=./examples/DisabledToggleButtonExample.tsx
```
### ToggleButtonGroup
You can group related Toggle buttons easily with a `ToggleButtonGroup` out of box. To control the selected state of its child buttons, both `value` and `onChange` props must be provided.
```jsx file=./examples/DefaultToggleButtonGroupExample.tsx
```
To make your toggle button group exclusive, set the `isExclusive` prop to `true`.
```jsx file=./examples/ExclusiveToggleButtonGroupExample.tsx
```
In cases where you need to have at least one option on, you can set the `isSelectionRequired` prop to `true`.
```jsx file=./examples/SelectionRequiredToggleButtonGroupExample.tsx
```
Press me!
```jsx
Press me!
```
## CSS Styling
```tsx file=./examples/ToggleButtonThemeExample.tsx
```
### Target classes
### Global styling
To override styling on all ToggleButtons, you can set the Amplify CSS variables or use the built-in `.amplify-togglebutton` class.
{'Press me!'}
```css
:root {
--amplify-components-togglebutton-color: var(--amplify-colors-purple-60);
}
.amplify-togglebutton {
color: var(--amplify-colors-purple-60);
}
```
```jsx
Press me!
```
### Local styling
To override styling on a specific ToggleButton, you can use (in order of increasing specificity): a class selector, data attributes, or style props.
_Using a class selector:_
Press me!
```css
.my-togglebutton {
border-radius: 20px;
}
```
```jsx
Press me!
```
_Using data attributes:_
{'Press me!'}
```css
.amplify-togglebutton[data-variation='primary'] {
color: var(--amplify-colors-blue-60);
}
```
```jsx
'Press me!'
```
_Using style props:_
```jsx file=./examples/ToggleButtonStylePropsExample.tsx
```